// pages/mine/identification/identification.ts
import { dateFormat } from "../../utils/util"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showDate: false,
        currentDate: new Date().getTime(),
        minDate: new Date().getTime(),
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            }
            if (type === 'month') {
                return `${value}月`;
            }
            return value;
        },
        date: '',  //选择的时间
        maxDate: 0,
        active: '-1',
        custom: 0,
        scrollTop: 0
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        let date = new Date('2028-11-22');
        this.setData({
            maxDate: date.getTime()
        })
    },
    onShow() {
        this.adaptation()
    },
    // 适配高度
    adaptation() {
        const that = this;
        setTimeout(function () {
            var query = wx.createSelectorQuery();
            query.select('.timer').boundingClientRect();
            query.select('.tab').boundingClientRect();
            query.select('.topTitle').boundingClientRect();
            query.select('.topSearch').boundingClientRect();
            query.exec(function (rect) {
                console.log(rect)
                if (rect[0] === null) return;
                let num = 0;
                rect.forEach(element => {
                    if (element != null) {
                        num += element.height
                    }
                });
                console.log(num)
                that.setData({
                    // 标题 + 搜索框 + 滑动栏 + 底部栏  + 适配距离
                    custom: num
                })
            });
        }, 500)
    },
    // 选择日期
    chooseDate() {
        this.setData({
            showDate: true
        })
    },
    // 确认日期
    confirmDate(e: any) {
        let currentDate = e.detail
        console.log(currentDate)
        let date = dateFormat(currentDate)
        this.setData({
            date,
            currentDate,
            showDate: false
        })
    },
    // 取消选择日期
    cancelDate() {
        this.setData({
            showDate: false
        })
    },
    share() {
        wx.navigateTo({
            url: "./share/index"
        })
    },
    changeTab() {
        this.setData({
            scrollTop: 0
        })
    },
})